package com.homemanager.management;

import com.homemanager.entities.DatabaseObject;
import com.homemanager.management.interfaces.IRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Valiantsin_Vlasau on 6/20/13.
 */
public class Repository<T extends DatabaseObject> extends RepositoryBase<T> implements IRepository<T> {
    @Override
    public T get(int id) {
        if (contains(id)){
            for (T item : collection){
                if (item.getId() == id)
                    return item;
            }
        }
        return null;
    }

    @Override
    public void add(T item) {
        if (!collection.contains(item)){
            collection.add(item);
        }
    }

    @Override
    public void delete(int id) {
        if (contains(id)){
            T item = get(id);
            collection.remove(item);
        }
    }

    @Override
    public void update(T item) {
        if (collection.contains(item)){
            T oldItem = get(item.getId());
            oldItem = item;
        }
    }
}
